package com.arpa.oms.controller;

import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.map.MapUtil;
import com.arpa.core.web.MediaTypes;
import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.wms.domain.consts.PropertyConst;
import com.arpa.wms.domain.dto.BatchRuleDTO;
import com.arpa.wms.domain.dto.BatchRuleFormDTO;
import com.arpa.wms.domain.entity.BatchRule;
import com.arpa.wms.domain.enums.StatusEnum;
import com.arpa.wms.domain.vo.BatchRuleVO;
import com.arpa.wms.service.IBatchRuleService;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * Oms批次规则 Controller
 * </p>
 *
 * @author wangdong
 * @since 2021-07-21
 */
@Api(tags = "批次规则")
@RestController
@RequestMapping(value="/omsBatchRule", produces = "application/json;charset=UTF-8")
@Log4j2
public class OmsBatchRuleController {

   @Autowired
   private IBatchRuleService iBatchRuleService;

    /**
     * 获取 批次规则 列表
     *
     * @param batchRuleDTO
     * @param request
     * @return
     */
    @ApiOperation(value = "获取 批次规则 列表", notes = "获取 批次规则 列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
        @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = BatchRuleVO.class))
    @NeedLogin
    @GetMapping()
    public Result list(BatchRuleDTO batchRuleDTO, HttpServletRequest request) {
        try {

            batchRuleDTO.setShipmentCode(UserUtil.getLoginWarehouseCodeOrShipmentCode());
            BatchRuleVO batchRuleVOSum = iBatchRuleService.queryListSum(batchRuleDTO);
            List<BatchRuleVO> batchRuleVOList = iBatchRuleService.queryList(batchRuleDTO);

            Page returnPage = new Page(batchRuleDTO.getPageNum(),batchRuleDTO.getPageSize());
            returnPage.setRecords(batchRuleVOList);
            returnPage.setTotal(batchRuleVOSum.getTotal());
            returnPage.setSumObject(batchRuleVOSum);
            return Result.ok().data(returnPage);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }

}
